<template>
	<view>
		<button @click="login">登录</button>
		<input type="text" v-model="token">
		<button @click="alipay">支付宝支付</button>
		<input type="text" v-model="rechargeid">
		<button @click="recharge">充值</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rechargeid: 1,
				token: ''
			}
		},
		onLoad() {

		},
		methods: {
			login() {
				uni.getUserProfile({
					desc: '获取用户详细信息',
					success(res) {
						uni.login({
							provider: 'weixin',
							scopes: 'auth_user',
							onlyAuthorize: true,
							success(e) {
								console.log(res)
								console.log(e)
								uni.request({
									url: 'https://greenoil.open258.top/index.php/api/user/mpLogin',
									method: 'POST',
									data: {
										code: e.code,
										iv: res.iv,
										encryptedData: res.encryptedData,
										loginType: 1,
									}
								}).then(res => {
									console.log(res)
								})
							},
							complete(e) {
								console.log(e)
							}
						})
					}
				})
			},
			alipay() {
				uni.requestPayment({
					"provider": "alipay",
					 //此处为服务器返回的订单信息字符串
					"orderInfo": 'app_id=2021003159621092&method=alipay.trade.app.pay&format=JSON&return_url=https%3A%2F%2Fyansongda.cn%2Falipay%2Freturn&charset=utf-8&sign_type=RSA2&timestamp=2022-11-01+17%3A21%3A50&version=1.0&notify_url=https%3A%2F%2Fgreenoil.open258.top%2Findex.php%2Fapi%2Falipay%2FrechargeSuccess&app_cert_sn=d8c9b54a1cad2b7f0d113b6a57866b61&alipay_root_cert_sn=687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6&biz_content=%7B%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22out_trade_no%22%3A1667294510%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22yansongda+%5Cu6d4b%5Cu8bd5+-+01%22%2C%22quit_url%22%3A%22https%3A%5C%2F%5C%2Fyansongda.cn%22%7D&sign=RddiJ%2B5d0iAobvTp07Jv62a%2FZ2u1LvdisaKF%2BwJxjIb65Bl9TI4n54Jo5W1gbGR5x0F4h3JEZULxizIFJRUNHIOIlnD5F2ABosXQU3sP9dfO0KDPjOlvjzl%2Frt2NQJyDoZoQjddhratl4M1IhvOlwMTS0Hrr0FV6LpHGaCI2%2B%2Fe8YgTmNczigf83E0tU467L2yBZe6SwNauArDEmpas5ObADVUcex%2FL4F94jMhWpI8tLuvFepsx4lYTsA8XCC6NdpSQzHRRxkd9dAgKPudY0815FtIaP83A60BDpkU6My5z%2BqGg3rMZaTzfZ52%2FdvILhjxbLlHjC9ECnNrbtyiz%2Fug%3D%3D',
					success: function(res) {
						var rawdata = JSON.parse(res.rawdata);
						console.log("支付成功");
					},
					fail: function(err) {
						console.log('支付失败:' + JSON.stringify(err));
					}
				});
			},
			recharge() {
				uni.request({
					url: 'https://greenoil.open258.top/index.php/api/recharge/recharge?id=3&channel=0&payway=wechat',
					method: 'get',
					header: {
						"ba-user-token": this.token
					},
					success(res) {
						wx.requestPayment({
							timeStamp: res.data.data.payment.timeStamp,
							nonceStr: res.data.data.payment.nonceStr,
							package: res.data.data.payment.package,
							signType: res.data.data.payment.signType,
							paySign: res.data.data.payment.paySign,
							success(res) {
								console.log(res)
							},
							fail(res) {
								console.log(res)
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>
